home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Prograph Classic 2.6.1 / Prograph Reference Manual / Prograph Reference 1-4 / Prograph Reference 1-4.rsrc / TEXT_157.txt < prev    next >
Encoding:
Text File  |  1995-10-21  |  8.0 KB  |  185 lines

  1.  
  2. t Access to Events *158*
  3.  
  4. This section describes how your application can respond to Apple Events, and how to modify the event handling capabilities of the System Classes.
  5.  
  6. The Prograph Classic System Classes provide access to Macintosh events. The Macintosh Event Manager creates an event every time a user clicks the mouse, presses a key, or inserts a disk. Other events occur when your application‚Äôs windows need to be redrawn and when your application is brought to the foreground or sent to the background. 
  7.  
  8. For many types of applications you can use the System Classes as they are: all events will be handed automatically for you. However, by passing all events to your application, Prograph gives you the flexibility to modify the behavior of the System Classes to suit the needs of your application. 
  9.  
  10. Events in Prograph*158*
  11.  
  12. Events are passed to your application through a method, called Notify, in class Application. Every time an event occurs Notify is called, with three inputs: the current application, a Macintosh event record, and an integer which represents the type of event. For most events, Notify calls other methods to actually process the event. Classes Application, Window, Window Item, Canvas, Scroll List and Edit Text contain event handling methods. These methods use a set of Prograph primitives, called the System Class primitives, to aid in event handling. 
  13.  
  14. Apple Events*158*
  15.  
  16. Apple events are a new type of event for Macintosh System 7. They allow communication between applications on a single computer or across a network. For example, an Apple event is sent to your application when the user double-clicks on one of your application‚Äôs documents. 
  17.  
  18. There are four events called required events, which your application must respond to in order to be System 7 friendly. These are Open Application, Open Documents, Print Documents and Quit Application. *158*
  19.  
  20. Every Apple event is identified by a four character Event Class and a four character Event ID. The four required events, for example, all have the same class but different IDs:*159*
  21.  
  22. Apple Event              Class          ID    
  23.  
  24. Open Application         ‚Äòaevt‚Äô         ‚Äòoapp‚Äô    
  25.  
  26. Open Documents         ‚Äòaevt‚Äô           ‚Äòodoc‚Äô    
  27.  
  28. Print Documents      ‚Äòaevt‚Äô         ‚Äòpdoc‚Äô    
  29.  
  30. Quit Application          ‚Äòaevt‚Äô          ‚Äòquit‚Äô     
  31.  
  32. The Event Class is used to group related Apple events into event suites. The four events with class ‚Äòaevt‚Äô make up the Required suite. Other suites include the Core suite, the Text suite, and the Graphical suite. 
  33.  
  34. Besides class and ID, Apple events contain information about the sender of the event and other event-specific data. For example, the Open Document event contains a list of documents to be opened by your application. The Apple Event Manager has a collection of Macintosh methods for extracting information from Apple events.
  35.  
  36. In the Prograph System Classes, the attribute aevent methods of class Application is used to control Apple events which are received by your application. For each Apple event you wish to support, you specify the Event Class, the Event ID, and the method to be called when that event is received. The Application Editor contains an Apple Events button which opens the Apple Event Editor. *159*
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. The Apple Event Editor includes three fields for entering an Event Class, Event ID, and the name of the method which is to respond to that combination. When the Insert button is pressed, these are then inserted into a scrolling list of such Apple Event Class/ID/Method triplets. A triplet in the scrolling list may be selected and then edited or deleted.*160*
  61.  
  62. When your Prograph application receives an Apple event, the Notify method is called, just as it is for any other type of event. Three System Class primitives are used to dispatch Apple events: sc-aevent-begin, sc-aevent-dispatch and sc-aevent-end. sc-aevent-begin returns the Event Class and Event ID as well as the Apple event record and a default reply. The Apple event record contains all of the information associated with the Apple event. The Apple Event Manager automatically creates a default reply which is sent back to the sending application when you call sc-aevent-end. If you encounter an error while processing the Apple Event you can add error information to the default reply. sc-aevent-dispatch searches the aevent methods attribute and returns the method associated with the Event Class and Event ID. If it doesn‚Äôt find a matching method, it returns NULL.*160*
  63.  
  64. Handling Events Yourself*160*
  65.  
  66. As mentioned earlier, events are passed to your application through the Notify method in class Application. Notify has three inputs: the current application, the event record, and the type of event. What follows is a brief description of events and event records; for more detailed information see Inside Macintosh. *160*
  67.  
  68. A Macintosh event record contains the event code, where and when the event occurred, and other information specific to each type of event. An event record contains the following fields:*161*
  69.  
  70. what      the event code (mouseDown, keyDown, etc.)
  71.  
  72. where      the location of the mouse when the event occurred, in global coordinates
  73.  
  74. when      the time the event occurred in ticks (sixtieths of a second) since system 
  75.                    startup
  76.  
  77. message      depends on the event code
  78.  
  79. modifiers      depends on the event code
  80.  
  81. The what field*161*
  82.  
  83. The what field contains an event code which identifies the type of event. This is passed as the third input to Notify for easy access. The event codes are available in Prograph as Macintosh constants. The most common events are:
  84.  
  85. nullEvent      No other event is pending.
  86.  
  87. mouseDown      The user pressed the mouse button.
  88.  
  89. keyDown      The user pressed a key on the keyboard.
  90.  
  91. autoKey      The user is holding down a key.
  92.  
  93. updateEvt      A window needs to be redrawn.
  94.  
  95. activateEvt      One of your application‚Äôs windows has been selected (made the
  96.                           frontmost, active window), or deselected.
  97.  
  98. osEvt      Your application has been suspended (switched into the background), or
  99.                   resumed (brought into the foreground).
  100.  
  101. kHighLevelEvent      An Apple event has been sent to your application.
  102.  
  103. Other events which most applications will not need to handle are:  keyUp, mouseUp, networkEvt, diskEvt, driverEvt, app1Evt, app2Evt, and app3Evt.
  104.  
  105. The message field*161*
  106.  
  107. The event message contains information pertinent to keyDown, activate, update and suspend/resume events. For keyDown events the message contains, among other things, the ASCII code of the character that was typed. The code fragment below illustrates how to extract the character from the event message of a keyDown event.
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. For activate and update events the event message contains a pointer to the Macintosh window record of the affected window. Use the primitive sc-get-wind to find the Prograph window affected by update and activate events.*162*
  129.  
  130. When the event code is osEvt, the event message indicates whether your application is being suspended or resumed. If the message is an even number (bit 0 is off) your application is being suspended; if the message is an odd number (bit 0 is on) your application is being resumed. The figure below illustrates how to test the event message of an osEvt event.*162*
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. The modifiers  field*162*
  148.  
  149. The event modifiers apply to key and activate events. For activate events, bit 0 indicates whether the affected window is being activated or deactivated. If bit 0 is on, the window is being activated; if bit 0 is off, the window is being deactivated. The code below illustrates how to test the event modifiers of an activate event.*162*
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. For key events the modifiers indicate the state of the modifier keys: Command, option, shift, control, and caps lock. The figure below illustrates how to determine the state of the modifier keys in Prograph.*163*
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. cmdKey is a Macintosh constant used to extract the state of the command key. Use the constants shiftKey, alphaLock, optionKey and controlKey for the other modifier keys.*163*
  185.